<?php
require_once("/../eventClass.php");
require_once("/../databaseHelper.php");
require_once("/../resetDatabase.php");

class eventClassTest extends PHPUnit_Framework_TestCase
{	
	public function testGetEventDetails()
	{
		$DBEvent = eventClass::getEventDetails(1); 
		
		$event = array('USER_ID' => 7, 'NAME' => 'Starcraft Tournament',
		 'DESCRIPTION' => 'Starcraft tournament hosted by CSUAC', 'LOCATION' => 'CSEL',
		 'HOSTED_BY' => 'CSUAC', 'LINK' => null,
		 'IMAGE_PATH' => 'http://hijinksinc.com/wp-content/uploads/2010/06/starcraft_2.png',
		 'START_TIME' => '2011-12-10 12:00:00', 'END_TIME' => '2011-12-10 23:00:00',
		 'TAGS' => Array('1'=>'CSUAC',
						 '2'=>'Computer Science',
						 '6'=>'Gaming',
						 '7'=>'Engineering'));
		
		$this->assertEquals($DBEvent, $event);
	}
	
	public function testGetSimilarEvents()
	{
		$similarEvents = eventClass::getSimilarEvents(1);
		
		$first = eventClass::getEventDetails(2);
		$second = eventClass::getEventDetails(4);
		$third = eventClass::getEventDetails(7);
		
		$events = Array('2'=>$first, '4'=>$second, '7'=>$third);
		
		$this->assertEquals($similarEvents, $events);
	}
	
	public function testFindSimilarEventsWith3Events()
	{
		
		/* 
		 * Three Events
		 */
		$thisEvent = eventClass::getEventDetails(2);
		
		$thisEventTags = $thisEvent['TAGS'];
		//echo '<pre>'.print_r($thisEvent, true).'</pre>'; die();
		
		$similarIDs = Array('2','7','14');
	
		$similarEvents = eventClass::findSimilarEvents(1, $thisEventTags);
		
		$this->assertEquals($similarEvents, $similarIDs);
	
		
		/*
		 * Two Events
		 */
		$thisEvent = eventClass::getEventDetails(90);
		$thisEventTags = $thisEvent['TAGS'];
	
		$simIDs = Array('91','92','5');
	
		$similarEvents = eventClass::findSimilarEvents(90, $thisEventTags);
	
		$this->assertEquals($similarEvents, $simIDs);
	
		
		/*
		 * One Event
		 */
		$thisEvent = eventClass::getEventDetails(11);
		$thisEventTags = $thisEvent['TAGS'];
		
		$simIDs = Array('10','5','2');
		
		$similarEvents = eventClass::findSimilarEvents(11, $thisEventTags);
		
		$this->assertEquals($similarEvents, $simIDs);
		
		
		/*
		 * Zero Events
		 */
		$thisEvent = eventClass::getEventDetails(2);
		$thisEventTags = Array('19');//$thisEvent['TAGS'];
		
		$simIDs = Array('5','2','14');
		
		$similarEvents = eventClass::findSimilarEvents(2, $thisEventTags);
		
		$this->assertEquals($similarEvents, $simIDs);
	}
	
	public function testCreateNewEvent()
	{
		eventClass::createNewEvent('500', 'Billy Bobs Hoedown',
		'party for the ages', 'Billy Bobs House', 'Billy Bob',
		'google.com', 'test.jpg', '2011-12-25 21:00:00', '2011-12-26 3:00:00');
		
		$eventID = eventClass::getEventIDByEverything('500', 'Billy Bobs Hoedown',
		'party for the ages', 'Billy Bobs House', 'Billy Bob',
		'google.com', 'test.jpg', '2011-12-25 21:00:00' , '2011-12-26 03:00:00');
		
		$thisEvent = eventClass::getEventDetails($eventID);
		
		$arrayOfEverything = Array('USER_ID'=>'500', 'NAME'=>'Billy Bobs Hoedown',
		'DESCRIPTION'=>'party for the ages', 'LOCATION'=>'Billy Bobs House', 'HOSTED_BY'=>'Billy Bob',
		'LINK'=>'google.com', 'IMAGE_PATH'=>'test.jpg', 'START_TIME'=>'2011-12-25 21:00:00' , 'END_TIME'=>'2011-12-26 03:00:00');
		
		$this->assertEquals($thisEvent, $arrayOfEverything);
		
		// Delete the event after the test is over.
		$sql = "delete from test_bb.events where USER_ID=500";
		database::insertSQL($sql, true);
	}
	
	public function testGetEventIDByEverything()
	{
		$eventID = eventClass::getEventIDByEverything('7', 'Starcraft Tournament',
		'Starcraft tournament hosted by CSUAC', 'CSEL', 'CSUAC', null,
		'http://hijinksinc.com/wp-content/uploads/2010/06/s...', '2011-12-10 12:00:00', '2011-12-10 23:00:00');
		
		$this->assertEquals($eventID, 1);
	}
	
	public function testAddTagToNewEvent()
	{
		eventClass::addTagToNewEvent(1, 24);
		
		$DBEvent = eventClass::getEventDetails(1);
		
		$event = Array('1'=>'CSUAC',
					   '2'=>'Computer Science',
			   		   '6'=>'Gaming',
					   '7'=>'Engineering',
					   '24'=>'rec center');
		
		// Assert the added tag exists in the database where
		// we put it.
		$this->assertEquals($DBEvent['TAGS'], $event);
		
		$sql = "delete from test_bb.event_has_tag where EVENT_ID=1 and TAG_ID=24 limit 1";
// 		echo $sql; die();
		database::insertSQL($sql, true);
	}
}

?>